package com.example.demo;


import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("/request")//和浏览器进行连接，既可以是类路径，也可以是方法路径，要先加类路径，支持get/post
public class RequestController {

    @RequestMapping("/getHeader")
    public String getHeader(HttpServletRequest request) {
        String userAgent = request.getHeader("User-Agent");
        return "userAgent :" + userAgent;
    }


    @RequestMapping("/getHeader2")
    public String getHeader2(@RequestHeader("User-Agent") String userAgent) {
        return "userAgent :" + userAgent;
    }

}
